/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.quickorm.sample.serviceimpl;

import com.quickorm.sample.dao.UserDao;
import com.quickorm.sample.entity.User;
import com.quickorm.sample.service.UserService;
import java.util.List;
import java.util.UUID;

/**
 *
 * @author aaa
 */
public class UserServiceImpl implements UserService {

    private UserDao userDao;

    /**
     * @param 设置userDao
     */
    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }

    @Override
    public List<User> getAllUserList() {
        return userDao.getUserListWithRole();
    }

    @Override
    public User saveOrUpdateUser(User user) {
        if (user.getUserId() == null) {
            user.setUserId(UUID.randomUUID().toString().replace("-", ""));
            //保存
            userDao.save(user);
        } else {
            //更新
            userDao.update(user);
        }
        return user;
    }

    @Override
    public void deleteUser(String userId) {
        userDao.delete(User.class, userId);
    }

    @Override
    public void deleteUserByLoginName(String loginName) {
        userDao.deleteUserByLoginName(loginName);
    }
}
